package com.taoyibao.hongcanting.ui.entertainment.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.taoyibao.hongcanting.base.activity.BaseActivityNoSlidePresenter;
import com.taoyibao.hongcanting.base.delegate.ToolbarDelegate;
import com.taoyibao.hongcanting.base.delegate.WebViewDelegate;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.constant.ApiRoute;
import com.taoyibao.hongcanting.interfaces.InterfaceH5Leaderboard;
import com.taoyibao.hongcanting.interfaces.WebInteraction;
import com.taoyibao.hongcanting.utils.LogUtils;

/**
 * @author TangAnna
 * @description: 排行榜
 * @date :${DATA} 15:07
 */
public class LeaderboardActivity extends BaseActivityNoSlidePresenter<WebViewDelegate> implements InterfaceH5Leaderboard, ToolbarDelegate.OnLeftCilckListener {

    @Override
    protected Class<WebViewDelegate> getDelegateClass() {
        return WebViewDelegate.class;
    }

    /**
     * @param context
     */
    public static void open(Context context) {
        Intent intent = new Intent(context, LeaderboardActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        viewDelegate.setBackHeadGray();
        viewDelegate.setTitle("排行榜");
        viewDelegate.setWebViewLoadUrl(ApiRoute.LEADER_BOARD_WEB_PATH + "?token=" + SpUtils.getToken());
        LogUtils.dNormal("排行榜地址", ApiRoute.LEADER_BOARD_WEB_PATH + "?token=" + SpUtils.getToken());
        WebInteraction webInteraction = new WebInteraction(this);
        webInteraction.setH5Leaderboard(this);
        viewDelegate.setWebViewInterface(webInteraction);
    }

    /**
     * 获取到了H5传递的数据
     *
     * @param value
     */
    @Override
    public void getLeaderboardValue(final String value) {
        LogUtils.dNormal("webview", value);
        viewDelegate.mWebView.post(new Runnable() {
            @Override
            public void run() {
                LeaderboardSecondaryActivity.open(LeaderboardActivity.this, value);
            }
        });
    }

    @Override
    public void onLeftClick(View view) {
        if (viewDelegate.mWebView.canGoBack()) {
            viewDelegate.mWebView.goBack();
            viewDelegate.setTitle("排行榜");
        } else {
            finish();
        }
    }
}
